package com.lucun.es_transaction.controller;

import com.lucun.es_transaction.config.RolePermission;
import com.lucun.es_transaction.entity.Commodity;
import com.lucun.es_transaction.service.CommodityService;
import com.lucun.es_transaction.util.AuthorityUtil;
import com.lucun.es_transaction.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/commodity")
public class CommodityController {
    @Autowired
    CommodityService service;

    @RolePermission(role = AuthorityUtil.SECOND)
    @RequestMapping("/insert")//商品添加
    public JsonResult<?> insertSelective(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.insert(commodity, request);
    }

    @RolePermission(role = AuthorityUtil.THIRD)
    @RequestMapping("/selectByPrimaryKey")//商品查询/id
    public JsonResult<?> selectByPrimaryKey(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectByPrimaryKey(commodity, request);
    }

    @RolePermission(login = false)
    @RequestMapping("/selectBynumber")//商品编号查询
    public JsonResult<?> selectBynumber(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectBynumber(commodity, request);
    }

    @RolePermission(login = false)
    @RequestMapping("/selectByname")//商品查询/关键字
    public JsonResult<?> selectByname(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectByname(commodity, request);
    }
    @RolePermission(login = false)
    @RequestMapping("/selectBynameeva")//商品查询/关键字价格降序排列
    public JsonResult<?> selectBynameeva(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectBynameeva(commodity, request);
    }

    @RolePermission(login = false)
    @RequestMapping("/selectBynameASC")//商品查询/关键字价格升序排列
    public JsonResult<?> selectBynameASC(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectBynameASC(commodity, request);
    }
    @RolePermission(login = false)
    @RequestMapping("/selectBynameDESC")//商品查询/关键字价格降序排列
    public JsonResult<?> selectBynameDESC(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectBynameDESC(commodity, request);
    }
    @RolePermission(role = AuthorityUtil.SECOND)
    @RequestMapping("/updateByPrimaryKey")//商品下架
    public JsonResult<?> updateByPrimaryKey(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.updateByPrimaryKey(commodity, request);
    }

    @RolePermission(role = AuthorityUtil.SECOND)
    @RequestMapping("/updateByPrimaryKeySelective")//商品信息修改
    public JsonResult<?> updateByPrimaryKeySelective(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.updateByPrimaryKeySelective(commodity, request);
    }

    @RolePermission(login = false)
    @RequestMapping("/selectBycategory")//商品查询/分类
    public JsonResult<?> selectBycategory(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.selectBycategory(commodity, request);
    }
    @RolePermission(login = false)
    @RequestMapping("/getuserId")//个人商品发布查询
    public JsonResult<?> getuserId(@RequestBody Commodity commodity, HttpServletRequest request) {
        return service.getuserId(commodity, request);
    }

}
